<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>后台登录-X-admin1.1</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="./css/font.css">
		<link rel="stylesheet" href="./css/xadmin.css">
		<link rel="stylesheet" href="https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css">
		<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="./js/xadmin.js"></script>

	</head>
	<body>
		<!-- 中部开始 -->
		<div class="wrapper">
			<!-- 右侧主体开始 -->
			<div class="page-content">
				<div class="content">
					<!-- 右侧内容框架，更改从这里开始 -->
					<form class="layui-form" action="../../api/manage/modifyUser.form">
						<div class="layui-form-item">
							<label for="L_email" class="layui-form-label">
								邮箱
							</label>
							<div class="layui-input-inline">
								<input type="text" id="L_email" name="email" autocomplete="off" class="layui-input">
							</div>
							<!-- <div class="layui-form-mid layui-word-aux">
								如果您在邮箱已激活的情况下，变更了邮箱，需
								<a href="/user/activate/" style="font-size: 12px; color: #4f99cf;">
									重新验证邮箱
								</a>
								。
							</div> -->
							<input type="hidden" name="id" />
						</div>
						<div class="layui-form-item">
							<label for="L_tel" class="layui-form-label">
								手机
							</label>
							<div class="layui-input-inline">
								<input type="text" id="L_tel" name="phone" required lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label for="L_city" class="layui-form-label">
								年龄
							</label>
							<div class="layui-input-inline">
								<input type="text" id="L_city" name="age" autocomplete="off" class="layui-input">
							</div>
						</div>
						
						<div class="layui-form-item">
							<label for="L_city" class="layui-form-label">
								性别
							</label>
							<div class="layui-inline">
								<div class="layui-input-inline">
									<input type="radio" name="sex" value="男" title="男">
									<input type="radio" name="sex" value="女" title="女">
									<input type="radio" name="sex" value="保密" title="保密">
								</div>
							</div>
						</div>
						
						<div class="layui-form-item">
							<label for="L_sign" class="layui-form-label">
							</label>
							<!-- <button class="layui-btn" key="set-mine" lay-filter="save" lay-submit onclick="save()">
								保存
							</button> -->
							<input type="submit"  class="layui-btn" />
						</div>
					</form>
					<!-- 右侧内容框架，更改从这里结束 -->
				</div>
			</div>
			<!-- 右侧主体结束 -->
		</div>
		<!-- 中部结束 -->
		<script>
			function getQueryVariable(variable) {
				let query = window.location.search.substring(1);
				let vars = query.split("&");
				for (let i = 0; i < vars.length; i++) {
					let pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1];
					}
				}
				return (false);
			}
			
			$(function(){
				var id = getQueryVariable("userId");
				$.ajax({
					url: "../../api/manage/getUserById.form/userId/"+id,
					type: "get",
					success: function(data) {
						var obj = $(".layui-form");
						obj.find("input[name='email']").val(data.email);
						obj.find("input[name='id']").val(id);
						obj.find("input[name='phone']").val(data.phone);
						obj.find("input[name='age']").val(data.age);
						if(data.sex=='男'){
							$("input[type='radio']").each(function(i,e){
								if(e.value=='男'){
									$(e).prop("checked",true)
								}
							});
						}else if(data.sex=='女'){
							$("input[type='radio']").each(function(i,e){
								if(e.value=='女'){
									$(e).prop("checked",true)
								}
							});
						}else{
							$("input[type='radio']").each(function(i,e){
								if(e.value=='保密'){
									$(e).prop("checked",true)
								}
							});
						}
					},
					error: function(error) {
						console.log(error);
						if (error.status == 403) {
							window.location.href = "login.html";
						}
					}
				});
			})
			
			$(".layui-form").submit(function() {
				var email = $("#L_email").val();
				var tel = $("#L_tel").val();
				if (email != "") {
					/* var reg = /^[0-9]{6,18}\@([a-zA-Z0-9]{2,6})\.com$/; */
					var reg = /^[0-9][0-9]{5,10}\@([a-zA-Z0-9]{2,6})\.com$/;
					var isok = reg.test(email);
					if (!isok) {

						layer.msg("邮箱格式不正确，请重新输入！");
						/* $("#L_email").focus(); */
						return false;
					}
				};
				if (tel != "") {
					var reg = /^([0-9]{11})$/;
					var t1 = reg.test(tel);
					if (!t1) {
						layer.msg("手机格式不正确，请重新输入！");
						/* $("#L_tel").focus(); */
						return false;
					}
				}
				layer.msg("修改成功");
				parent.location.reload();
				return true;
				
			});
		</script>
	</body>
</html>
